#include "jsonrpcnotificationhandler.h"

#include <QDebug>

#include "jsonrpcservice.h"

JsonRpcNotificationHandler::JsonRpcNotificationHandler(const QString& methodName, QObject* instance, const char *slot)
{
    v_methodName = methodName;
    v_automaticHandle = true;

    v_slot.p_object = instance;
    v_slot.v_slotName = QString(slot);
}


JsonRpcMessage JsonRpcNotificationHandler::notification() const{
    return v_notification;
}


void JsonRpcNotificationHandler::setAutomaticHandle(bool enable){
    v_automaticHandle = enable;
}

bool JsonRpcNotificationHandler::getAutomaticHandle() const {
    return v_automaticHandle;
}

void JsonRpcNotificationHandler::processNotification(const JsonRpcMessage&){
    if(v_automaticHandle){
        //QObject *obj = v_slot.p_object;
        QVariant returnValue;

        /*int error = */
        JsonRpcService::invokeSlot(v_slot.p_object, v_slot.v_slotName, v_notification.params(), returnValue);
        //qDebug() << "ERROR = " << error;
    }else{
        Q_EMIT received();
    }
}
